package controller

type MyCode int64 //自定义MyCode类型

const ( //使用 const 关键字定义了一组错误码，每个错误码都是 MyCode 类型的常量。
	CodeSuccess                  MyCode = 1000
	CodeInvalidParams            MyCode = 1001
	CodeUserExist                MyCode = 1002
	CodeUserPhoneOrEmailNotExist MyCode = 1003
	CodeInvalidPassword          MyCode = 1004
	CodeServerBusy               MyCode = 1005
	CodeInvalidToken             MyCode = 1006
	CodeNoAuth                   MyCode = 1007
	CodeInvalidAuthFormat        MyCode = 1008
	CodeCaptchaExpired           MyCode = 1009
	CodeCaptchaError             MyCode = 1010
	CodeUserPhoneExist           MyCode = 1011
	CodeTaskNotReceive           MyCode = 1012
	CodeTaskImageComplete        MyCode = 1013
	CodeFileLoadError            MyCode = 1014
	CodeNotTask                  MyCode = 1015
	CodeNeedLogin                MyCode = 1016
	CodeReceiveFailed            MyCode = 1017
	CodeDownFailed               MyCode = 1018
)

var msgFlags = map[MyCode]string{ //map类型,映射错误码和信息
	CodeSuccess:                  "success",
	CodeInvalidParams:            "请求参数错误",
	CodeUserExist:                "用户昵称已存在",
	CodeUserPhoneExist:           "用户手机号已存在",
	CodeUserPhoneOrEmailNotExist: "手机号或密码不存在",
	CodeInvalidPassword:          "密码不正确",
	CodeServerBusy:               "服务繁忙",
	CodeInvalidToken:             "无效的Token",
	CodeInvalidAuthFormat:        "认证格式不正确",
	CodeNoAuth:                   "没有权限",
	CodeCaptchaExpired:           "验证码过期了",
	CodeCaptchaError:             "验证码不正确",
	CodeTaskNotReceive:           "该任务已被申领过",
	CodeTaskImageComplete:        "图片已经上传",
	CodeFileLoadError:            "文件加载错误",
	CodeNotTask:                  "没有任务",
	CodeNeedLogin:                "需要登录",
	CodeReceiveFailed:            "领取任务失败",
	CodeDownFailed:               "下架任务失败",
}

func (c MyCode) Msg() string { //把上边两个连起来，传入code，传出code对应的信息
	//当调用 Msg 方法时，会查找 msgFlags 中是否存在对应的错误信息，
	//如果存在则返回，否则返回默认的错误信息，例如 CodeServerBusy 对应的信息。
	msg, ok := msgFlags[c]
	if ok {
		return msg
	}
	return msgFlags[CodeServerBusy]
}
